package com.ct.gd.passport.domain;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.util.Log;

import com.ct.gd.passport.common.connect.CtServer;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Protocol;
import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.up91.common.android.connect.Params;

public class PassportApplyResult {

	@SerializedName("id")
	private int id;

	@SerializedName("time")
	private String time;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public static PassportApplyResult load(PassportGoApply apply) {
		if (apply == null) {
			return null;
		}
		Params params = new Params();
		params.put(Protocol.SubmitArgs.ARG_PASS_TYPE, "1");
		params.put(Protocol.SubmitArgs.ARG_DISTRICT, apply.getAreaValue());
		params.put(Protocol.SubmitArgs.ARG_SERIALNUMBER, apply.getPassportId());
		params.put(Protocol.SubmitArgs.ARG_VALIDATE, apply.getPassLimitDate());
		try {
			params.put(Protocol.SubmitArgs.ARG_NAME, URLEncoder.encode(apply.getName(), "utf-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		params.put(Protocol.SubmitArgs.ARG_PHONE, apply.getPhoneNumber());
		params.put(Protocol.SubmitArgs.ARG_GOAREA, apply.getArea());
		params.put(Protocol.SubmitArgs.ARG_TYPE, apply.getGoType());
		params.put(Protocol.SubmitArgs.ARG_EXPRESS, apply.getEms());
		params.put(Protocol.SubmitArgs.ARG_EXPRESS_NAME, apply.getEmsName());
		params.put(Protocol.SubmitArgs.ARG_EXPRESS_ADRESS, apply.getEmsAddr());
		params.put(Protocol.SubmitArgs.ARG_EXPRESS_CODE, apply.getPostCord());

		if (Config.ON_LINE) {
			String result = CtServer.getServer().doPost(Protocol.Commands.PASSPORT_SUBMIT, params);
			result = result.replace("\"Data\":\"\"", "Data:null");
			Log.i("dbug", "ApplyResult:" + result);
			PassportApplyResult resultGson = new Gson().fromJson(result, PassportApplyResult.class);
			return resultGson;
		}
		return null;
	}

}
